﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace NG
{
    class ProjectKsf
    {
        private string tableName = "[dbo].[ProjectKsf]";
        public void addProjectKSF(Project pro, KSF ksf ,int weight)
        {
            DBConnect con = new DBConnect();
            string tbn = "[" + con.dbName + "]." + this.tableName;
            if (con.OpenConnection() == false)
            {
                throw new System.Exception("Couldn't connect to the Database");
            }
            string query = string.Format("INSERT INTO " + tbn + " (projectNo,ksfNo,ksfWeight) VALUES ({0},{1},{2})",
                pro.ID, ksf.ksfCode, weight);
           



            SqlCommand cmd = new SqlCommand(query, con.connection);
            cmd.ExecuteNonQuery();

            if (con.CloseConnection() == false)
            {
                throw new System.Exception("Couldn't disconnect from the Database");
            }
        }

        public void deleteProjectKsf(Project pro ,KSF ksf)
        {
            DBConnect con = new DBConnect();
            string tbn = "[" + con.dbName + "]." + this.tableName;

            if (con.OpenConnection() == false)
            {
                throw new System.Exception("Couldn't connect to the Database");
            }

            string query = string.Format("DELETE FROM " + tbn + " WHERE projectNo = {0} AND ksfNo = {1} ", pro.ID,ksf.ksfCode);
            SqlCommand cmd = new SqlCommand(query, con.connection);
            cmd.ExecuteNonQuery();

            if (con.CloseConnection() == false)
            {
                throw new System.Exception("Couldn't disconnect from the Database");
            }
        }


    }

}
